package jmine.tec.report.script;

import jmine.tec.script.ScriptLogger;
import jmine.tec.script.persistent.context.impl.AbstractScriptExecutionContext;

/**
 * Interface do contexto de execução de scripts de relatório
 * 
 * @author lundberg
 */
public class CreateReportScriptExecutionContextImpl extends AbstractScriptExecutionContext<ReportScriptResult> implements
        CreateReportScriptExecutionContext {

    private static final String PARAMETER = "parameter";

    private static final String RESULT = "result";

    private static final String TRACER = "tracer";
    
    private static final String LOG = "logger";
    
    private StringBuilder tracer = new StringBuilder();

    private ReportScriptResult result = new ReportScriptResult();

    /**
     * {@inheritDoc}
     */
    public CreateReportScriptExecutionContext prepare(Object parameter) {
        this.getParameters().putParameter(PARAMETER, parameter);
        return this;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void beforeExecution() {
        super.beforeExecution();
        this.getParameters().putParameter(TRACER, this.tracer);
        this.getParameters().putParameter(RESULT, this.result);
        this.getParameters().putParameter(LOG, this.result.getScriptLogger(), ScriptLogger.class);
    }

    /**
     * {@inheritDoc}
     */
    public ReportScriptResult getResult() {
        return this.result;
    }

    /**
     * {@inheritDoc}
     */
    public String getTracer() {
        return this.tracer.toString();
    }
}
